using Curriculum.Services;
using Modelo.Clases;

namespace ConcursoCV.UI.WebUserControls.Concurso
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	/// <summary>
	///		Summary description for RankingConcursoDetalle.
	/// </summary>
	public class RankingConcursoDetalle : System.Web.UI.UserControl
	{
		protected System.Web.UI.WebControls.Label lblDocente;
		protected System.Web.UI.WebControls.Repeater rptJurados;
		protected System.Web.UI.WebControls.Label lblCalificacionTotal;
		protected System.Web.UI.WebControls.Button btnVolver;

		private const string pidConcursoRanking = "027";

		private void Page_Load(object sender, System.EventArgs e)
		{
			if( !this.IsPostBack )
			{
				this.ConcursoId = this.Request["concursoId"];
				this.DocenteId = this.Request["docenteId"];
				this.CargarForm();
			}
		}

		private void CargarForm( )
		{
			ConcursoService service = new ConcursoService();
			ResultadoCalificacionCV objResultado = service.ObtenerResultado( ConcursoId, DocenteId );
			lblDocente.Text = objResultado.NombreDocente;
			lblCalificacionTotal.Text = objResultado.PuntajeTotal.ToString();

			rptJurados.DataSource = objResultado.ItemsCalificacion;
			rptJurados.DataBind();
		}

		private void RedirigirAConcursoRanking()
		{
			string url = "Default.aspx?pid=" + pidConcursoRanking + "&concursoId=" + this.ConcursoId + "&docenteId=" + this.DocenteId + GetParametroTipo();
			Server.Transfer(url);			
		}

		private string GetParametroTipo()
		{
			string tipoParam = string.Empty;
			if (this.Request["type"] != null)
			{
				tipoParam = "&type=" + this.Request["type"];
			}
			return tipoParam;
		}

		#region - properties -

		public string ConcursoId
		{
			get{ return (string)ViewState["_concursoId"];}
			set{ ViewState["_concursoId"] = value;}
		}
		
		public string DocenteId
		{
			get{ return (string)ViewState["_docenteId"];}
			set{ ViewState["_docenteId"] = value;}
		}

		#endregion - properties -

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btnVolver.Click += new System.EventHandler(this.btnVolver_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnVolver_Click(object sender, System.EventArgs e)
		{
			this.RedirigirAConcursoRanking();
		}
	}
}
